package com.jingdianjichi.subject.domain.handler.subject;

import com.jingdianjichi.subject.common.enums.ISDeletedFlagEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoTyperEnum;
import com.jingdianjichi.subject.domain.entity.SubjectAnswerBo;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBo;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 单选题目的策略类
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{
    @Override
    public SubjectInfoTyperEnum getHandlerType() {
        return SubjectInfoTyperEnum.BRIEF;
    }
    @Resource
    private SubjectBriefService subjectBriefService;
    @Override
    public void add(SubjectInfoBo subjectInfoBo) {
        //简单题目插入
        SubjectBrief subjectBrief=new SubjectBrief();

        subjectBrief.setSubjectId(subjectInfoBo.getId());
        subjectBrief.setSubjectAnswer(subjectInfoBo.getSubjectAnswer());
        subjectBrief.setIsDeleted(ISDeletedFlagEnum.UN_DELETE.getCode());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBo query(Integer subjectId) {
        SubjectBrief subjectBrief = subjectBriefService.queryById(Long.valueOf(subjectId));
        SubjectOptionBo subjectOptionBo=new SubjectOptionBo();
        subjectOptionBo.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return subjectOptionBo;
    }

}
